﻿using Abp.Dependency;
using GN.Pay.Core.Services;
using GN.Pay.Core.Values;
using Microsoft.AspNet.SignalR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GN.Pay.Utils;
using Microsoft.AspNet.SignalR.Hubs;
using System.Threading.Tasks;
using System.Dynamic;

namespace GN.Pay.GatewayWeb.JumpNotify
{
    /// <summary>
    /// 跳转通知Hub
    /// </summary>
    [HubName("notifyHub")]
    public class JumpNotifyHub : Hub, ITransientDependency
    {
        /// <summary>
        /// 注册申请
        /// </summary>
        /// <param name="applyId"></param>
        /// <returns></returns>
        public async Task RegisterApply(string applyId)
        {
            if (string.IsNullOrWhiteSpace(applyId))
            {
                return;
            }
            await Task.Run(() =>
            {
                var session = new HubSession(applyId, Context.ConnectionId, Clients.Caller);
                HubSessionManager.RegisterSession(session);
            });
        }

        /// <summary>
        /// 断开
        /// </summary>
        /// <param name="stopCalled"></param>
        /// <returns></returns>
        public override async Task OnDisconnected(bool stopCalled)
        {
            await Task.Run(() =>
             {
                 HubSessionManager.RemoveSessionForConnect(Context.ConnectionId);                 
             });
            await base.OnDisconnected(stopCalled);
        }        
    }
}